package com.wdzg.member.generate.freemaker.generator.element;

import java.io.File;
import java.util.HashMap;

import com.wdzg.member.generate.freemaker.generator.BaseGenerator;
import com.wdzg.member.generate.freemaker.generator.GeneratorHtml;
import com.wdzg.member.generate.freemaker.generator.bean.XmlBean;

public class ControllerGenerator extends BaseGenerator {

	public ControllerGenerator(XmlBean bean) {
		super(bean);
	}

	@Override
	public boolean generatorHtml(String ftlPath) {
		try {
			ftlFile = new File(ControllerGenerator.class.getResource("/").getPath() + ftlPath);
			
			HashMap<String, Object> contextMap = new HashMap<String, Object>();
			contextMap.put("title", bean.title);
			contextMap.put("modular", bean.modular);
			contextMap.put("modelName", bean.modelName);
			contextMap.put("className", bean.className);
			contextMap.put("tableName", bean.tableName);
			contextMap.put("entityClass", bean.className);
			contextMap.put("controllerClass", bean.className +"Controller");
			contextMap.put("serviceClass", bean.className +"Service");
			contextMap.put("visitUrl", bean.path.visitUrl);
			
			GeneratorHtml generator = new GeneratorHtml();
			generator.geneHtmlFile("controller.ftl", ftlFile.getPath(), contextMap, getPathWithEnd(bean.path.cjava), bean.className +"Controller.java");
			
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return false;
	}
}
